#version 450

// vertex data
layout (location = 0) in vec3 inPosition;
layout (location = 1) in vec3 inNormal;

// Instanced data
layout (location = 2) in vec3 inOffset;

layout (binding = 0) uniform UBO 
{
	mat4 proj;
	mat4 view;
	mat4 model;
	vec3 scale;
} ubo;

layout (location = 0) out vec3 outPosition;
layout (location = 1) out vec3 outNormal;

void main() {

    gl_Position = ubo.proj * ubo.view * ubo.model * vec4(inOffset + ubo.scale * inPosition, 1.0);
   	
	vec4 posView = ubo.view * ubo.model * vec4(inOffset + ubo.scale * inPosition, 1.0);
	outPosition = posView.xyz/posView.w;

	const mat4 normalMat = transpose(inverse(ubo.view * ubo.model));
    outNormal = vec3(normalMat * vec4(inNormal, 0.0));
}


